package com.blb.mybatis.controller;

import com.blb.mybatis.dto.LogisticsSearch;
import com.blb.mybatis.entity.Goods;
import com.blb.mybatis.entity.GoodsAddress;
import com.blb.mybatis.entity.Logistics;
import com.blb.mybatis.service.GoodsAddressService;
import com.blb.mybatis.service.GoodsService;
import com.blb.mybatis.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class LogisticsMapperController {
    @Autowired
    private GoodsAddressService goodsAddressService;

    @Autowired
    private LogisticsService logisticsService;

    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/getALL")
    public String selectAll(Model model) {
        List<LogisticsSearch> logisticsSearches = logisticsService.selectAllLogistics();
        model.addAttribute("logisticsSearches", logisticsSearches);
        return "logisticsList";
    }

    @RequestMapping("/getALLGoodsAddressAndGoods")
    public String selectAllGoods(Model model) {
        List<GoodsAddress> goodsAddresses = goodsAddressService.selectAll();
        List<Goods> goods = goodsService.selectAll();
        model.addAttribute("goods", goods);
        model.addAttribute("goodsAddresses", goodsAddresses);
        return "addLogistics";
    }

    @RequestMapping("/getALLGoodsAddressAndGoods2")
    public String selectAllGoods2(Model model) {
        List<GoodsAddress> goodsAddresses = goodsAddressService.selectAll();
        List<Goods> goods = goodsService.selectAll();
        model.addAttribute("goods", goods);
        model.addAttribute("goodsAddresses", goodsAddresses);
        return "updateLogistics";
    }

    @RequestMapping("/addL")
    public String addLogistics(Logistics logistics) {
        logisticsService.addLogistics(logistics);
        return "redirect:/getALL";
    }

    @RequestMapping("/delL")
    public String delLogistics(long id) {
        logisticsService.delLogistics(id);
        return "redirect:/getALL";
    }

    @RequestMapping("/updateL")
    public String updateLogistics(Logistics logistics) {
        logisticsService.updateLogistics(logistics);
        return "redirect:/getALL";
    }


}
